package pers.wensheng.patterns.behavioral_pattern.visitor_pattern.extend.double_dispatch;

class Animal {
    public void accept(Execute exe) {
        exe.execute(this);
    }
}

class Dog extends Animal {
    public void accept(Execute exe) {
        exe.execute(this);
    }
}

class Cat extends Animal {
    public void accept(Execute exe) {
        exe.execute(this);
    }
}

class Execute {
    public void execute(Animal a) {
        System.out.println("animal");
    }

    public void execute(Dog d) {
        System.out.println("dog");
    }

    public void execute(Cat c) {
        System.out.println("cat");
    }
}

/**
 * 双分派技术
 */
public class Client {
    public static void main(String[] args) {
        Animal a = new Animal();
        Animal d = new Dog();
        Animal c = new Cat();

        Execute exe = new Execute();
        a.accept(exe);
        d.accept(exe);
        c.accept(exe);
    }
}
